package com.shun.gen.service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class GenCodeUtils {

	public final static String CRUD_PREFIX = "export const tableOption =";
	public final static String AVUE_INDEX_VUE_VM = "avue/index.vue2.vm";
	public final static String AVUE_API_JS_VM = "avue/api.js.vm";
	public final static String AVUE_CRUD_JS_VM = "avue/crud.js.vm";

	/**
	 * 配置
	 *
	 * @return
	 */
	public static List<String> getTemplates() {
		List<String> templates = new ArrayList<>();
//		templates.add("template/avue/api.js.vm");
		templates.add("template/avue/index.vue2.vm");
		templates.add("template/avue/crud.js.vm");
		return templates;
	}
	
	/**
	 * 不出现列
	 * @return
	 */
	public static List<String> closeColumns(){
		List<String> closeColumns = new ArrayList<>();
		closeColumns.add("version");
		closeColumns.add("del_flag");
		return closeColumns;
	}
	
	/**
	 * 隐藏列
	 * @return
	 */
	public static List<String> hideColumns(){
		List<String> hideColumns = new ArrayList<>();
		hideColumns.add("sort");
		hideColumns.add("date_created");
		hideColumns.add("date_updated");
		hideColumns.add("create_user");
		hideColumns.add("update_user");
		return hideColumns;
	}
	
	/**
	 * 检查列是否属于不上
	 * @param columnName
	 * @return
	 */
	public static boolean checkColumnClose(String columnName) {
		return closeColumns().contains(columnName);
	}
	
	/**
	 * 检查列是否属于不显示
	 * @param columnName
	 * @return
	 */
	public static boolean checkColumnHide(String columnName) {
		return hideColumns().contains(columnName);
	}
	
	/**
	 * 获取文件名
	 */
	public static String getFileName(String template, String parentPath, String pathName, String packageName,
			String moduleName) {

		if (template.contains(AVUE_INDEX_VUE_VM)) {
			return parentPath + File.separator + "src" + File.separator + "views" + File.separator
					+ pathName + File.separator + "index.vue";
		}
		if (template.contains(AVUE_API_JS_VM)) {
			return parentPath + File.separator + "src" + File.separator + "api"+ File.separator+moduleName
					+ File.separator + pathName + ".js";
		}
		if (template.contains(AVUE_CRUD_JS_VM)) {
			return parentPath + File.separator + "src" + File.separator + "const" + File.separator + "crud"
					+ File.separator+moduleName+ File.separator + pathName + ".js";
		}
		return null;
	}
}
